package model

import (
	"database/sql/driver"
	"encoding/json"
	"tdy-backend/app/core/model"
)

type Scene struct {
	model.BaseModel
	MemberId   uint       `gorm:"column:member_id;type:bigint(20);not null;comment:会员id"`
	WorksId    uint       `gorm:"column:works_id;type:bigint(20);not null;comment:作品id"`
	MaterialId uint       `gorm:"column:material_id;type:bigint(20);not null;comment:素材id"`
	GroupId    uint       `gorm:"column:group_id;type:bigint(20);not null;comment:分组id"`
	Kind       int        `gorm:"column:kind;type:tinyint(4);not null;comment:类型 1普清 2高清"`
	Title      string     `gorm:"column:title;type:varchar(100);not null;comment:标题"`
	Path       string     `gorm:"column:path;type:varchar(200);not null;comment:路径"`
	Info       *SceneInfo `gorm:"column:info;type:json;default:null;comment:全景信息"`
	Lat        float64    `gorm:"column:lat;type:decimal(10,6);default:null;comment:纬度""`
	Lng        float64    `gorm:"column:lng;type:decimal(10,6);default:null;comment:经度""`
	Alt        int        `gorm:"column:alt;type:int(11);default:null;comment:高度"`
}

type SceneInfo struct {
	TileSize   int
	Levels     int
	Resolution string
}

func (o SceneInfo) Value() (driver.Value, error) {
	return json.Marshal(o)
}

func (o *SceneInfo) Scan(input interface{}) error {
	if input == nil {
		return nil
	}
	return json.Unmarshal(input.([]byte), o)
}
